package com.lzx.lizhenxing.user.utils;

import com.lzx.lizhenxing.delivery.dao.DeliveryPersonTaskDao;
import com.lzx.lizhenxing.delivery.model.DeliveryPersonTaskModel;
import com.lzx.lizhenxing.point.utils.PointUtils;
import com.lzx.lizhenxing.sys.dao.UserDao;
import com.lzx.lizhenxing.sys.model.User;
import com.lzx.lizhenxing.user.dao.UserExpressDeliveryDao;
import com.lzx.lizhenxing.user.dao.UserOrderDao;
import com.lzx.lizhenxing.user.model.UserExpressDeliveryModel;
import com.lzx.lizhenxing.user.model.UserOrderModel;
import com.lzx.lizhenxing.user.service.ExpressDeliveryService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class OrderUtils {


    @Resource
    private UserOrderDao userOrderDao;

    @Resource
    private UserExpressDeliveryDao userExpressDeliveryDao;

    @Resource
    private ExpressDeliveryService expressDeliveryService;

    @Resource
    private UserDao userDao;

    @Resource
    private DeliveryPersonTaskDao deliveryPersonTaskDao;

    @Resource
    private PointUtils pointUtils;


    public void payByPoint(Long uid, UserOrderModel orderModel, UserExpressDeliveryModel edModel){
        User user = userDao.selectById(uid);
        Integer newPoint = user.getPoint() - 10;
        user.setPoint(newPoint);
        userDao.updateById(user);
        // 设置订单状态为已支付
        orderModel.setStatus(1);
        // 设置支付方式为积分支付
        orderModel.setPayType(1);
        // 设置快递状态为代取中2
        edModel.setStatus(2);
        // 并将配送员任务表添加任务
        DeliveryPersonTaskModel taskModel = new DeliveryPersonTaskModel();
        taskModel.setUserOrderId(orderModel.getId());
        taskModel.setUid(orderModel.getDeliveryPersonId());
        taskModel.setStatus(0);
        taskModel.setUserExpressDeliveryId(edModel.getId());
        deliveryPersonTaskDao.insert(taskModel);
    }

}
